import Vue from 'vue'
import VueRouter from 'vue-router'
import AvueRouter from './avue-router'
import PageRouter from './page/index'
import routes from './routes'
import Store from 'src/store'

Vue.use(VueRouter)

/*
 * If not building with SSR mode, you can
 * directly export the Router instantiation;
 *
 * The function below can be async too; either use
 * async/await or return a Promise which resolves
 * with the Router instance.
 */
let Router;
export default function (/* { store, ssrContext } */) {
   Router = new VueRouter({
    scrollBehavior: () => ({ x: 0, y: 0 }),
    // routes,
    routes,
    // Leave these as they are and change in quasar.conf.js instead!
    // quasar.conf.js -> build -> vueRouterMode
    // quasar.conf.js -> build -> publicPath
    mode: process.env.VUE_ROUTER_MODE,
    base: process.env.VUE_ROUTER_BASE
  });

  AvueRouter.install(Router, Store);
  Router.$avueRouter.formatRoutes(Store.state.common.menu, true);
  Router.addRoutes([...PageRouter]);

  return Router
}

export const router = () => {
  return Router
}
